/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tp1.controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Hashtable;
import javax.swing.JPanel;
import tp1.views.Principal;

/**
 *
 * @author tulio
 */
public abstract class Controller implements ActionListener {

    public static final int EVENTO_ABRIR_TELA_CLIENTE = 1;
    public static final int EVENTO_SALVAR_CLIENTE = 2;
    public static final int EVENTO_APAGAR_CLIENTE = 3;
    public static final int EVENTO_NOVO_CLIENTE = 4;
    public static final int EVENTO_EDITAR_CLIENTE = 5;
    public static final int EVENTO_BUSCAR_CLIENTE = 6;
    public static final int EVENTO_RELATORIO_CLIENTE = 7;

    public static final int EVENTO_ABRIR_TELA_PLANO = 1;
    public static final int EVENTO_SALVAR_PLANO = 2;
    public static final int EVENTO_APAGAR_PLANO = 3;
    public static final int EVENTO_NOVO_PLANO = 4;
    public static final int EVENTO_EDITAR_PLANO = 5;
    public static final int EVENTO_BUSCAR_PLANO = 6;

    public static final int EVENTO_ABRIR_TELA_LINHA = 1;
    public static final int EVENTO_SALVAR_LINHA = 2;
    public static final int EVENTO_APAGAR_LINHA = 3;
    public static final int EVENTO_NOVO_LINHA = 4;
    public static final int EVENTO_EDITAR_LINHA = 5;
    public static final int EVENTO_BUSCAR_LINHA = 6;
    public static final int EVENTO_RELATORIO_LINHA = 7;

    public static final int EVENTO_ABRIR_TELA_CHAMADA = 1;
    public static final int EVENTO_SALVAR_CHAMADA = 2;
    public static final int EVENTO_APAGAR_CHAMADA = 3;
    public static final int EVENTO_NOVO_CHAMADA = 4;
    public static final int EVENTO_EDITAR_CHAMADA = 5;
    public static final int EVENTO_BUSCAR_CHAMADA = 6;

    public static final int MENU_CLIENTE = 1;
    public static final int MENU_PLANO = 2;
    public static final int MENU_LINHA = 3;
    public static final int MENU_CHAMADA = 4;
    
    public static final int CONTROLLER_CLIENTE = 1;
    public static final int CONTROLLER_PLANO = 2;
    public static final int CONTROLLER_LINHA = 3;
    public static final int CONTROLLER_CHAMADA = 4;

    protected JPanel view;
    private Hashtable<Object, Integer> components;

    protected Controller(JPanel view) {
        this.view = view;
        this.components = new Hashtable<Object, Integer>();
    }

    public static Controller factory(int controller, JPanel view) {
        Controller c = null;
        switch (controller) {
            case Controller.CONTROLLER_CLIENTE:
                c = ClienteController.getInstance(controller, view);
                break;
            case Controller.CONTROLLER_PLANO:
                c = PlanoController.getInstance(controller, view);
                break;
            case Controller.CONTROLLER_CHAMADA:
                c = ChamadaController.getInstance(controller, view);
                break;
            case Controller.CONTROLLER_LINHA:
                c = LinhaController.getInstance(controller, view);
                break;
        }
        return c;
    }

    public void actionPerformed(ActionEvent e) {
        action(this.components.get(e.getSource()));
    }

    public void addEvent(Object o, int event) {
        components.put(o, event);
    }

    public abstract void action(int event);

    public void abrirAction() {
        Principal.getInstance().showView(view);
    }
}
